import type { IResponseBody } from "@/common/Responsetypes";
import http from "./request";
import type { IJournalOmit } from "@/components/journalList/journalList.vue";
import type { IJournal } from "@/common/JournalTypes";

export function add(data: object): Promise<IResponseBody<object>> {
  return http.post("/journals", data);
}

export function modify(data: object): Promise<IResponseBody<object>> {
  return http.put("/journals", data);
}

export function del(id: number): Promise<IResponseBody<object>> {
  return http.delete(`/journals/${id}`);
}

/**
 * 查找关联指定 marker 的日志列表的初略信息
 * @param mid marker id
 * @returns
 */
export function findByMid(mid: number): Promise<IResponseBody<IJournal>> {
  return http.get(`/journals`, {
    params: {
      mid,
    },
  });
}

/**
 *
 * @param mid marker id
 * @returns
 */
export function findByid(id: number): Promise<IResponseBody<IJournal>> {
  return http.get(`/journals/findById`, {
    params: {
      id,
    },
  });
}

export function findOpenJournal(
  mid: number,
  uid: number
): Promise<IResponseBody<IJournalOmit[]>> {
  return http.get(`/journals/findOpenJournal`, {
    params: {
      mid,
      uid,
    },
  });
}
export function findOneOpenJournal(
  mid: number,
  uid: number,
  id: number
): Promise<IResponseBody<IJournal>> {
  return http.get(`/journals/findOneOpenJournal`, {
    params: {
      mid,
      uid,
      id,
    },
  });
}
